﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Planisoft.Entities;
using Microsoft.Practices.Unity;
using Planisoft.BL;

namespace Planisoft.ClienteMvcWeb.Controllers
{
    public class PlanillaController : Controller
    {
        //
        // GET: /Planilla/
        [Dependency]
        public ItrabajadorBL TrabajadorBL{ get; set; }
        [Dependency]
        public IPlanillaDetalleBL PlanillaDetalleBL { get; set; }
        [Dependency]
        public IPlanillaBL PlanillaBL { get; set; }
        [Dependency]
        public IMesBL MesBL { get; set; }
        
        public ActionResult Index()
        {
            var listMesPlanilla = MesBL.GetAllFromMesPlanilla();
            ViewData["IdMes"] = new SelectList(listMesPlanilla, "IdMes", "DescMes");

            var listar = TrabajadorBL.GetAllFromTrabajadorByPlanilla();
            return View(listar);
        }
        public ActionResult ListarPlanilla() 
        {
            var Listar = PlanillaBL.GetAllfromPlanilla();
            return View(Listar);
        }
    


        //POST: /Planilla/Create by trabajador
        [HttpPost]
        public ActionResult GenerarPlanilla(Int32 id, Int32 Anio, Int32 Mes) 
        {
            try
            {
                // TODO: Add insert logic here
                
                //PlanillaDetalleBL.AddPlanillaDetalle(planillaDetalle);
                PlanillaDetalleBL.AddPlanillaDetalle(id, Anio, Mes);
                var msg = new { exito = true, msg = "Planilla Generada, para el trabajador: " + id.ToString() };
                return Json(msg, JsonRequestBehavior.AllowGet);

                //return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        
        //
        // GET: /Planilla/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Planilla/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Planilla/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /Planilla/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Planilla/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Planilla/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Planilla/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
